import { FlowTypeEnum, FieldTypeEnum } from '@/api/enum';
import { VxeColumnProps } from '@/components/VxeTable';
import type { SelectProps } from 'ant-design-vue';
import { EleTag } from 'ele-admin-pro';
import { h } from 'vue';

export interface ColumnsFrom extends VxeColumnProps {
  formHidden?: boolean;
  fieldType?: FieldTypeEnum;
  defaultValue?: string;
  isRow?: boolean;
  options: any;
  disabled: boolean;
  FkData: SelectProps['options'];
}

export default [
  {
    title: '编码',
    field: 'code',
    isRow: false,
    formHidden: false,
    fieldType: FieldTypeEnum.Input,
    options: {
      allowClear: true
    }
  },
  {
    title: '名称',
    field: 'name',
    isRow: false,
    formHidden: false,
    fieldType: FieldTypeEnum.Input
  },
  {
    title: '类型',
    field: 'format',
    slots: {
      default: ({ row }) => {
        const format = row.format;
        for (const key in FlowTypeEnum) {
          if (Object.prototype.hasOwnProperty.call(FlowTypeEnum, key)) {
            const element = FlowTypeEnum[key];
            if (format == key && element) {
              return h(EleTag, { color: 'blue' }, () => element);
            }
          }
        }
      }
    },
    FkData: () => {
      const data = [] as SelectProps['options'];
      for (const key in FlowTypeEnum) {
        if (Object.prototype.hasOwnProperty.call(FlowTypeEnum, key)) {
          const element = FlowTypeEnum[key];
          data?.push({ value: key, label: element });
        }
      }
      return data;
    },
    isRow: false,
    formHidden: false,
    fieldType: FieldTypeEnum.Select
  },
  {
    title: '前缀',
    field: 'prefix',
    isRow: false,
    formHidden: false,
    fieldType: FieldTypeEnum.Input
  },
  {
    title: '流水位数',
    field: 'digit',
    isRow: false,
    formHidden: false,
    fieldType: FieldTypeEnum.InputNumber
  },
  {
    title: '流水号',
    field: 'mantissa',
    isRow: false,
    formHidden: false,
    fieldType: FieldTypeEnum.InputNumber
  },
  {
    width: 140,
    title: '操作',
    align: 'center',
    slots: { default: 'action' },
    fixed: 'right'
  }
] as ColumnsFrom[];
